#include "qbullet.h"

QBullet::QBullet(const QString & fileName,QGraphicsScene *scence,qreal angle):QpimapItem(fileName,scence)
{
    this->scence=scence;
    qreal dx,dy;
    qreal rad;
    rad=angle*3.14/180;
    dx=120*cos(rad);
    dy=120*sin(rad);

    this->setPos(scence->width()/2+dx,scence->height()-dy);
    this->setRotation(90-angle);

}

void QBullet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
     painter->drawPixmap(-pixmap.width()/2,-pixmap.height(),pixmap);
     if(this->collidingItems().count()>0)
     {
         docolling();
     }

}

void QBullet::advance(int phase)
{
   if(mapToScene(0,0).x()<=0||mapToScene(0,0).x()>=1269)
   {
       delete this;
   }
   else
   {
    this->setPos(mapToScene(0,-20));
   }
}

void QBullet::docolling()
{


    QList<QGraphicsItem*> list=this->collidingItems();
    QList<QGraphicsItem*>::Iterator i;
    Qfish *fish;
    i=list.begin();
    while(i!=list.end())
    {
       fish=(Qfish*)(*i);
       fish->fish_death();
       i++;
    }
    delete this;
}
